package com.sdtv.basemodule.image;

import android.content.Context;
import android.widget.ImageView;

/**
 * @ProjectName: MediunFusion
 * @Package: com.sdtv.basemodule.image
 * @ClassName: ImageLoaderDelegate
 * @Description: 加载图片的代理类。该类持有了实现ImageLoaderInterface的具体实现类，当更换图片加载
 * 框架的时候，只需要重写一个图片加载类即可，该类可以在Applicaiton中init.指定图片加载框架
 * @Author: 小郭同学
 * @CreateDate: 2019-07-08 16:50
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class ImageLoaderDelegate implements ImageLoaderInterface {

    //里面定义一个processor 这个是加载图片的具体实现
    // 更换框架的时候 只需要写一个processor实现imageLoaderInterface 实现加载图片方法即可
    public static volatile ImageLoaderInterface processor;


    /**
     * 单例模式 创建加载图片的工具类
     *
     * @param imageLoader
     */
    public static ImageLoaderInterface init(ImageLoaderInterface imageLoader, ImageConfig config) {
        if (null == processor) {
            synchronized (ImageLoaderDelegate.class) {
                if (null == processor) {
                    processor = imageLoader;
                    processor.setImageConfig(config);
                }
            }
        }
        return processor;
    }


    @Override
    public void setImageConfig(ImageConfig imageConfig) {

    }

    @Override
    public void loadImageFromNet(Context context, ImageView imageView, String url) {
        processor.loadImageFromNet(context, imageView, url);
    }

    @Override
    public void loadImageFromSd(Context context, ImageView imageView, String filePath) {
        processor.loadImageFromSd(context, imageView, filePath);

    }

    @Override
    public void loadImageFromAssert(Context context, ImageView imageView, int resourceId) {
        processor.loadImageFromAssert(context, imageView, resourceId);
    }

    @Override
    public void loadImageFormNet(Context context, ImageView imageView, String url,
                                 int placeHolderId, int errorId,
                                 int radius, ImageView.ScaleType scaleType) {
        processor.loadImageFormNet(context, imageView, url, placeHolderId, errorId, radius, scaleType);
    }

    @Override
    public void loadImageFormSd(Context context, ImageView imageView, String filePath,
                                int placeHolderId, int errorId, int radius,
                                ImageView.ScaleType scaleType) {
        processor.loadImageFormSd(context, imageView, filePath, placeHolderId, errorId, radius, scaleType);
    }

    @Override
    public void loadCircleImgFromUrl(Context context, ImageView imageView, String url) {
        processor.loadCircleImgFromUrl(context, imageView, url);
    }

    @Override
    public void loadCircleImgFromSd(Context context, ImageView imageView, String filePath) {
        processor.loadCircleImgFromSd(context, imageView, filePath);
    }

    @Override
    public void loadImgWithRadius(Context context, ImageView imageView, String url, int radius) {
        processor.loadImgWithRadius(context, imageView, url, radius);
    }
}
